import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Payload {

	public static void main(String[] args) throws Exception {

		File file = new File("payload.txt");
		
		FileInputStream fileInputStream = new FileInputStream(file);


		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(
				(int) file.length());

		int buf_size = 1024;
		byte[] buffer = new byte[buf_size];
		int len = 0;
	
		while (-1 != (len = fileInputStream.read(buffer, 0, buf_size))) {
			byteArrayOutputStream.write(buffer, 0, len);
		}

		BufferedOutputStream oop = new BufferedOutputStream(
				new FileOutputStream(new File("payloadoutput.txt")));

		XMLEncoder xmlEncoder = new XMLEncoder(oop);
		xmlEncoder.flush();
		xmlEncoder.writeObject(byteArrayOutputStream.toByteArray());
		xmlEncoder.close();
		byteArrayOutputStream.close();
		fileInputStream.close();

	}
}
